package server;

import java.io.*;
import java.net.*;
import java.util.*;

class TCPserver {
	public static Map<String, Socket> socketMap;
	public static Socket[] sockets;
	public static int numSocket = 0;
	
	public TCPserver() {
		socketMap = new HashMap<String, Socket>();
		sockets = new Socket[10];
		try {
			ServerSocket ss = new ServerSocket(1027);
			System.out.println("Listening on port 1027...");
			while (true) {	
				Socket connectionSocket = ss.accept();
			    sockets[numSocket] = connectionSocket;
			    socketMap.put((connectionSocket.getInetAddress()).getHostAddress(), connectionSocket);
			    SendThread st = new SendThread(connectionSocket);
			    st.start();
			    ReceiveThread rt = new ReceiveThread(connectionSocket);
				rt.start();
				numSocket++;		  
			}
		}
		  catch (Exception ex) {}
	}
		
	public static void main(String argv[]) throws Exception {
		TCPserver serverInstance = new TCPserver();
	}
}